package com.coolingme.FileInfo;

import java.io.File;
import java.util.Arrays;

/**
 * 文件后缀判断
 */
public class FileSuffixTest {

    public static void main(String[] args) {
        String s = "pic" + File.separator + "20190701000046" + File.separator + "1 (1).jpg";
        s = s.replace(File.separator, "/");
        System.out.println(s);

        String fileName = "1 (1).jpg";

        // 获取文件后缀
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);

        String allowPicSuffix[] = new String[]{"jpg", "png", "gif"};

//        if (fileName.endsWith("jpg")) {
//            System.out.println("11111111");
//        }
        boolean b = isHasSuffix(suffix, allowPicSuffix);

    }

    public static boolean isHasSuffix(String suffix, String allowPicSuffix[]) {
        // 后缀不为空
        if (suffix == null || "".equals(suffix) || suffix.trim().length() == 0) {
            return false;
        }
        //
//        for (String s : allowPicSuffix) {
//            if (suffix.indexOf(s) > -1) {
//                return true;
//            }
//        }
//        return false;
        boolean b = Arrays.asList(allowPicSuffix).contains(suffix);
        return b;
    }


}
